package m.jclecai.com.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import m.jclecai.com.R;
import m.jclecai.com.adapter.holder.NoticeHolder;
import m.jclecai.com.bean.Response.ResNewsList;

/**
 * Created by ZD on 2017/7/19.
 */

public class NoticeAdapter extends RecyclerView.Adapter<NoticeHolder> {

    private Context mContext;
    List<ResNewsList.NewsBean> mData;

    public NoticeAdapter(Context mContext,List<ResNewsList.NewsBean> data) {
        this.mContext = mContext;
        this.mData=data;
    }

    @Override
    public NoticeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new NoticeHolder(View.inflate(mContext, R.layout.item_notice,null));
    }

    @Override
    public void onBindViewHolder(NoticeHolder holder, final int position) {
        holder.init(mData.get(position));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void refreshData(List<ResNewsList.NewsBean> data){

        mData.clear();
        mData.addAll(data);
        notifyDataSetChanged();
    }


    public List<ResNewsList.NewsBean> getData() {
        return mData;
    }

    public interface OnItemClickListener{
        public void onItemClick(int position);
    }

    public OnItemClickListener mListener;

    public OnItemClickListener getListener() {
        return mListener;
    }

    public void setListener(OnItemClickListener listener) {
        mListener = listener;
    }
}
